package sg.edu.nus.iss.team8s.vmcs.PropertyLoader;
/**
 * 
 * @author Nie XiaoYi
 *
 */
import sg.edu.nus.iss.team8s.vmcs.beans.CashStoreItem;
import sg.edu.nus.iss.team8s.vmcs.beans.Coin;
import sg.edu.nus.iss.team8s.vmcs.beans.StoreItem;
import sg.edu.nus.iss.team8s.vmcs.control.MachineryController;

public class CashPropertyLoader extends FilePropertyLoader {
	
	private final String VALUEKEY = "Value";
	private final String WEIGHTKEY = "Weight";
	
	private static CashPropertyLoader instance = null;
	
	private CashPropertyLoader(String fileName) {
		super(fileName);
		// TODO Auto-generated constructor stub
	}
	
	public static synchronized CashPropertyLoader getInstance(String fileName){
		if(instance == null){
			instance = new CashPropertyLoader(fileName);
		}
		return instance;
	}
	
	public StoreItem getItem(int identifier){
		String name = getValue(this.NAMEKEY+String.valueOf(identifier));
		String value = getValue(this.VALUEKEY+String.valueOf(identifier));
		String weight = getValue(this.WEIGHTKEY+String.valueOf(identifier));
		String quantity = getValue(this.QUANTITYKEY+String.valueOf(identifier));
		Coin coin = new Coin(name,Integer.parseInt(weight),Integer.parseInt(value));
		StoreItem item = new CashStoreItem(Integer.parseInt(quantity),coin);
		return item;
	}
	
	public void setItem(int identifier, StoreItem cashItem){
		Coin coin = (Coin)cashItem.getContent();
		setValue(this.NAMEKEY+String.valueOf(identifier),coin.getName());
		setValue(this.VALUEKEY+String.valueOf(identifier),String.valueOf(coin.getValue()));
		setValue(this.WEIGHTKEY+String.valueOf(identifier),String.valueOf(coin.getWeight()));
		setValue(this.QUANTITYKEY+String.valueOf(identifier),String.valueOf(cashItem.getQuantity()));
	}
}
